<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="法人" prop="corporate">
        <el-input
          v-model="queryParams.corporate"
          placeholder="请输入法人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="类型" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择类型" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="经营范围" prop="manegeScope">
        <el-input
          v-model="queryParams.manegeScope"
          placeholder="请输入经营范围"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="成立日期" prop="foundDate">
        <el-date-picker clearable size="small"
          v-model="queryParams.foundDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择成立日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="经营期限" prop="manegeDeadline">
        <el-date-picker clearable size="small"
          v-model="queryParams.manegeDeadline"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择经营期限">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="网址" prop="website">
        <el-input
          v-model="queryParams.website"
          placeholder="请输入网址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="邮箱" prop="email">
        <el-input
          v-model="queryParams.email"
          placeholder="请输入邮箱"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="注册资本" prop="capital">
        <el-input
          v-model="queryParams.capital"
          placeholder="请输入注册资本"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="位置" prop="location">
        <el-input
          v-model="queryParams.location"
          placeholder="请输入位置"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="详细地址" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入详细地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="统一社会信用代码" prop="code">
        <el-input
          v-model="queryParams.code"
          placeholder="请输入统一社会信用代码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="固定电话" prop="telephone">
        <el-input
          v-model="queryParams.telephone"
          placeholder="请输入固定电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系人id" prop="contactId">
        <el-input
          v-model="queryParams.contactId"
          placeholder="请输入联系人id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="登记机关" prop="regOffice">
        <el-input
          v-model="queryParams.regOffice"
          placeholder="请输入登记机关"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="核准日期" prop="examineDate">
        <el-date-picker clearable size="small"
          v-model="queryParams.examineDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择核准日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="公司图片" prop="imageUrl">
        <el-input
          v-model="queryParams.imageUrl"
          placeholder="请输入公司图片"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户id" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核状态 [1：正在审核，2：审核通过，3：审核失败]" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择审核状态 [1：正在审核，2：审核通过，3：审核失败]" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['data:businessInfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['data:businessInfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['data:businessInfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['data:businessInfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="businessInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="businessId" />
      <el-table-column label="名称" align="center" prop="name" />
      <el-table-column label="法人" align="center" prop="corporate" />
      <el-table-column label="类型" align="center" prop="type" />
      <el-table-column label="经营范围" align="center" prop="manegeScope" />
      <el-table-column label="简介" align="center" prop="introduction" />
      <el-table-column label="成立日期" align="center" prop="foundDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.foundDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="经营期限" align="center" prop="manegeDeadline" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.manegeDeadline, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="网址" align="center" prop="website" />
      <el-table-column label="邮箱" align="center" prop="email" />
      <el-table-column label="注册资本" align="center" prop="capital" />
      <el-table-column label="位置" align="center" prop="location" />
      <el-table-column label="详细地址" align="center" prop="address" />
      <el-table-column label="统一社会信用代码" align="center" prop="code" />
      <el-table-column label="固定电话" align="center" prop="telephone" />
      <el-table-column label="联系人id" align="center" prop="contactId" />
      <el-table-column label="登记机关" align="center" prop="regOffice" />
      <el-table-column label="核准日期" align="center" prop="examineDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.examineDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="公司图片" align="center" prop="imageUrl" />
      <el-table-column label="审核所需资料" align="center" prop="examineImage" />
      <el-table-column label="用户id" align="center" prop="userId" />
      <el-table-column label="审核状态 [1：正在审核，2：审核通过，3：审核失败]" align="center" prop="status" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['data:businessInfo:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['data:businessInfo:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改企业信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入名称" />
        </el-form-item>
        <el-form-item label="法人" prop="corporate">
          <el-input v-model="form.corporate" placeholder="请输入法人" />
        </el-form-item>
        <el-form-item label="类型" prop="type">
          <el-select v-model="form.type" placeholder="请选择类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="经营范围" prop="manegeScope">
          <el-input v-model="form.manegeScope" placeholder="请输入经营范围" />
        </el-form-item>
        <el-form-item label="简介" prop="introduction">
          <el-input v-model="form.introduction" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="成立日期" prop="foundDate">
          <el-date-picker clearable size="small"
            v-model="form.foundDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择成立日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="经营期限" prop="manegeDeadline">
          <el-date-picker clearable size="small"
            v-model="form.manegeDeadline"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择经营期限">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="网址" prop="website">
          <el-input v-model="form.website" placeholder="请输入网址" />
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="form.email" placeholder="请输入邮箱" />
        </el-form-item>
        <el-form-item label="注册资本" prop="capital">
          <el-input v-model="form.capital" placeholder="请输入注册资本" />
        </el-form-item>
        <el-form-item label="位置" prop="location">
          <el-input v-model="form.location" placeholder="请输入位置" />
        </el-form-item>
        <el-form-item label="详细地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入详细地址" />
        </el-form-item>
        <el-form-item label="统一社会信用代码" prop="code">
          <el-input v-model="form.code" placeholder="请输入统一社会信用代码" />
        </el-form-item>
        <el-form-item label="固定电话" prop="telephone">
          <el-input v-model="form.telephone" placeholder="请输入固定电话" />
        </el-form-item>
        <el-form-item label="联系人id" prop="contactId">
          <el-input v-model="form.contactId" placeholder="请输入联系人id" />
        </el-form-item>
        <el-form-item label="登记机关" prop="regOffice">
          <el-input v-model="form.regOffice" placeholder="请输入登记机关" />
        </el-form-item>
        <el-form-item label="核准日期" prop="examineDate">
          <el-date-picker clearable size="small"
            v-model="form.examineDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择核准日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="公司图片" prop="imageUrl">
          <el-input v-model="form.imageUrl" placeholder="请输入公司图片" />
        </el-form-item>
        <el-form-item label="审核所需资料">
          <imageUpload v-model="form.examineImage"/>
        </el-form-item>
        <el-form-item label="用户id" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户id" />
        </el-form-item>
        <el-form-item label="审核状态 [1：正在审核，2：审核通过，3：审核失败]">
          <el-radio-group v-model="form.status">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listBusinessInfo, getBusinessInfo, delBusinessInfo, addBusinessInfo, updateBusinessInfo, exportBusinessInfo } from "@/api/data/businessInfo";

export default {
  name: "BusinessInfo",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 企业信息表格数据
      businessInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        corporate: null,
        type: null,
        manegeScope: null,
        introduction: null,
        foundDate: null,
        manegeDeadline: null,
        website: null,
        email: null,
        capital: null,
        location: null,
        address: null,
        code: null,
        telephone: null,
        contactId: null,
        regOffice: null,
        examineDate: null,
        imageUrl: null,
        examineImage: null,
        userId: null,
        status: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询企业信息列表 */
    getList() {
      this.loading = true;
      listBusinessInfo(this.queryParams).then(response => {
        this.businessInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        businessId: null,
        name: null,
        corporate: null,
        type: null,
        manegeScope: null,
        introduction: null,
        foundDate: null,
        manegeDeadline: null,
        website: null,
        email: null,
        capital: null,
        location: null,
        address: null,
        code: null,
        telephone: null,
        contactId: null,
        regOffice: null,
        examineDate: null,
        imageUrl: null,
        examineImage: null,
        userId: null,
        status: 0
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.businessId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加企业信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const businessId = row.businessId || this.ids
      getBusinessInfo(businessId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改企业信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.businessId != null) {
            updateBusinessInfo(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBusinessInfo(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const businessIds = row.businessId || this.ids;
      this.$confirm('是否确认删除企业信息编号为"' + businessIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delBusinessInfo(businessIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有企业信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportBusinessInfo(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
